﻿@model RentHouse.DTO.PermissionDTO
@{
    ViewBag.Title = "AddPer";
}

<div class="pd-20">

    <form class="form form-horizontal" id="form-admin-add" >
        <div class="row cl">
            <label class="form-label col-3"><span class="c-red">*</span>权限描述：</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" value="@Html.DisplayFor(Model=>Model.Description)" placeholder="权限描述" id="user-name" name="Description" datatype="*2-16" nullmsg="权限描述不能为空">
            </div>
            <div class="col-4"> </div>
        </div>
        <div class="row cl">
            <label class="form-label col-3"><span class="c-red">*</span>权限名字：</label>
            <div class="formControls col-5">
                <input type="text" placeholder="权限名字" autocomplete="off" value="@Html.DisplayFor(Model=>Model.Name)" class="input-text" datatype="*6-20" nullmsg="权限名字不能为空" name="Name" id="name">
                @Html.HiddenFor(Model => Model.Id)
            </div>
            <div class="col-4"> </div>
        </div>
        <div class="row cl">
            <div class="col-9 col-offset-3">
                <input class="btn btn-primary radius" type="button" id="btn_Add" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</div>


@section footScript{
    <script>

        function AddAndEdit(url, formObj) {
            $.post(url, formObj, function (data) {
                if (data.State == 1) {
                    layer.msg(data.ErrorMessage);
                    parent.location.reload();
                } else {
                    layer.msg(data.ErrorMessage);

                }

            }, "json")
        }

        $(function () {
            //对用户输入的信息进行校验
            //初始化验证控件
            var validform = $("#form-admin-add").Validform({ tiptype: 2 });
            $("#btn_Add").click(function () {
         
                var formObj = $("#form-admin-add").serializeArray();
                //当验证通过时，发送ajax请求
                if (validform.check(false)) {

                    var id = $("#Id").val()
                    if (id == "" || id == null) {

                        AddAndEdit('/Permission/AddPer', formObj);
                   
                    } else {
                        AddAndEdit('/Permission/EditPer', formObj);
                    }
            
                }




            })


        })
    </script>
     
    
    }

